{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "origin_pos": 0
   },
   "source": [
    "## 04循环神经网络"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-08-18T06:58:10.528336Z",
     "iopub.status.busy": "2023-08-18T06:58:10.527597Z",
     "iopub.status.idle": "2023-08-18T06:58:12.493106Z",
     "shell.execute_reply": "2023-08-18T06:58:12.492193Z"
    },
    "origin_pos": 2,
    "tab": [
     "pytorch"
    ]
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "from d2l import torch as d2l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-08-18T06:58:12.497284Z",
     "iopub.status.busy": "2023-08-18T06:58:12.496796Z",
     "iopub.status.idle": "2023-08-18T06:58:12.510001Z",
     "shell.execute_reply": "2023-08-18T06:58:12.508927Z"
    },
    "origin_pos": 5,
    "tab": [
     "pytorch"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[-1.6506, -0.7309,  2.0021, -0.1055],\n",
       "        [ 1.7334,  2.2035, -3.3148, -2.1629],\n",
       "        [-2.0071, -1.0902,  0.2376, -1.3144]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X, W_xh = torch.normal(0, 1, (3, 1)), torch.normal(0, 1, (1, 4))\n",
    "H, W_hh = torch.normal(0, 1, (3, 4)), torch.normal(0, 1, (4, 4))\n",
    "torch.matmul(X, W_xh) + torch.matmul(H, W_hh)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-08-18T06:58:12.513639Z",
     "iopub.status.busy": "2023-08-18T06:58:12.513360Z",
     "iopub.status.idle": "2023-08-18T06:58:12.520602Z",
     "shell.execute_reply": "2023-08-18T06:58:12.519678Z"
    },
    "origin_pos": 8,
    "tab": [
     "pytorch"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[-1.6506, -0.7309,  2.0021, -0.1055],\n",
       "        [ 1.7334,  2.2035, -3.3148, -2.1629],\n",
       "        [-2.0071, -1.0902,  0.2376, -1.3144]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "torch.matmul(torch.cat((X, H), 1), torch.cat((W_xh, W_hh), 0))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "required_libs": []
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
